package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
)

type R struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

func (r R) marshal(code int, msg string, data any) []byte {
	r.Msg = msg
	r.Code = code
	r.Data = data
	marshal, _ := json.Marshal(r)
	return marshal
}
func init() {
	log.SetFlags(log.Llongfile)
}

func main() {

	http.HandleFunc("/ws", gameWs)
	//启用一个线程处理消息数据
	go handle()
	err := http.ListenAndServe("0.0.0.0:80", nil)
	if err != nil {
		fmt.Println(err.Error())
	}

}
